package com.boat.sample.ddd.infrastructure.client;

import java.util.ArrayList;

import org.springframework.stereotype.Component;

import com.boat.sample.ddd.infrastructure.client.factory.LxrFactory;
import com.boat.sample.ddd.infrastructure.client.request.QueryKLineReq;
import com.boat.sample.ddd.infrastructure.client.response.LxrResponse;
import com.boat.sample.ddd.infrastructure.client.response.QueryKLineResp;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class LxrClient {

	public static final String token = "645aaa72-651b-49e4-bc35-1a50f575853c";

	private static final String kline_url = "https://open.lixinger.com/api/cn/company/candlestick";

	public LxrResponse<QueryKLineResp> queryKLine(String stockCode, String startDate) {
		QueryKLineReq queryKLineReq = LxrFactory.createQueryKLineReq(stockCode, startDate);
		String body = JSONUtil.toJsonStr(queryKLineReq);
		String result = HttpRequest.post(kline_url)
				.body(body)
				.execute().body();
		return JSONUtil.parse(result).toBean(new LxrResponse<QueryKLineResp>() {
		}.getClass());
	}

}
